﻿<html>
<head>
	<link href="/static/css/login.css" rel="stylesheet" type="text/css" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Chat Room</title>
	<script type="text/javascript" src="static/js/common.js"></script>
	<script type="text/javascript">
		function Init()
		{
			createroom();
			document.myform.usr.value = '';
			document.myform.usr.focus();
		}

		function createroom()
		{
			var xmlHttp;
			try
			{
				xmlHttp=new XMLHttpRequest();
			}
			catch (e)
			{

				try
				{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{

				try
			   {
			   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			   }
				catch (e)
			   {
			   alert("No support AJAX");
			   return false;
			   }
				}
			}

			xmlHttp.open("GET","/getroominfo",true);
    	xmlHttp.send("1");
    	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
    		{
    			//document.myform.usr.value = xmlHttp.responseText;
    			var p = trim(xmlHttp.responseText).split(";");
    			for(var i=0; i<p.length; ++i)
    			{
    				if(trim(p[i]) != "")
    				{
    					var roomname = p[i].split(",")[0];
    					var roomid   = p[i].split(",")[1];
    					//alert(roomname+roomid);
    					//创建房间
    					if(i == 0)
    					{
    						document.getElementById("room").innerHTML += "&nbsp;<input type='radio' name='room' onclick='myform.room.value="+roomid+";' checked='checked'>"+ roomname+"<br>";
    					}
    					else
    					{
    						document.getElementById("room").innerHTML += "&nbsp;<input type='radio' name='room' onclick='myform.room.value="+roomid+";'>"+ roomname+"<br>";
    					}

    				}
    			}
    			document.getElementById("room").innerHTML += "<br><br>";
    		}
    	}

		}
	</script>
</head>
<body onLoad="Init();">
<script type="text/javascript">

function check()
 {
 	var myname = document.myform.usr.value;
 	myname = trim(myname);
 	var flag = checkIfTab(myname);
 	if(flag == false)
 	{
 		alert("用户名非法");
 		Init();
 		return;
 	}
	if(myname == "")
	{
		alert("用户名不能为空");
		return;
	}
	var gender = document.myform.xb.value;
	var roomid = document.myform.roomid.value;
	//document.myform.usr.value = gender+","+roomid;
	login(myname,gender,roomid);
 }

function setCookie(name,value)
{
 var Days = 30;
 var exp = new Date();
 exp.setTime(exp.getTime() + Days*24*60*60*1000);
 document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function login(myname,gender,roomid)
 {
 var xmlHttp;
 try
    {
    xmlHttp=new XMLHttpRequest();
    }
 catch (e)
    {

   try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
   catch (e)
      {

      try
         {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
      catch (e)
         {
         alert("No support AJAX");
         return false;
         }
      }
    }

    xmlHttp.open("POST","/",true);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlHttp.send(myname+","+gender+","+roomid);
    xmlHttp.onreadystatechange=function()
    {
    	if(xmlHttp.readyState==4)
    	{
    		var errorno = xmlHttp.responseText.split(":")[0];
    		var info = xmlHttp.responseText.split(":")[1];
    		if(parseInt(errorno) < 0)
    		{
    			alert(info);
    			return;
    		}
    		else
    		{
    			//设置cookie
    			deleteCookie("ailiaousrname");
    			deleteCookie("roomid");
    			deleteCookie("gender");
    			setCookie("ailiaousrname",myname);
    			setCookie("roomid",roomid);
    			setCookie("gender",gender);
    			window.location.href = "/chat";
    		}
    	}
    }

 };
 </script>
 <div class="main">
	<div class="top_ad"><a href="#"><img border="0" width="100%" height="100%" src="/static/images/toplogin.jpg" /></a></div>
	<div class="loginpicture">the login image这做个google/本站搜索,搜索框,可以骗取流量</div>
	<div class="login">
	<form name="myform" method="post" >
		<div class="user_pwd">
		<br><label>&nbsp;『登陆』</lable><br><br>
		<label>&nbsp;&nbsp;账户:</lable>
		<input align="" type="text" name="usr" onKeyDown="if(event.keyCode==13)check();"><br>
		<!--<label>&nbsp;密码:</label>
		<input align="" type="password" name="pwd"  width="50px" onKeyDown=""><br>-->
		</div>
		<div class="sex">
		<label> &nbsp;&nbsp;性别:</label>
		&nbsp;<input type="radio" name="sex" onclick="myform.xb.value=1;" checked="checked" /> GG
		&nbsp;<input type="radio" name="sex" onclick="myform.xb.value=0;"/> MM<br><br><br>
		<input type="hidden" name="xb" value="1">
		</div>
		<div class="room" id="room">
		<label>&nbsp;『房间』</label><br><br>
		<input type="hidden" name="roomid" value="1001" >
		</div>
		<div class="ok_btn">
		&nbsp;<input type="button" value="马上进入" class="btn pbtn" onmouseover="this.style.borderColor='#75cd02'" onmouseout="this.style.borderColor='#dcdcdc'" onClick="check()">
		</div>
		<div class="reg_btn">
		<!--&nbsp;<input type="button" value="注册会员" onClick="">-->
		</div>
		<input type="text" size="0" style="visibility:hidden;">
	</form>
	</div>

	<div class="center_ad" id="center_ad" >the center flash ad</div>

	<div class="user_rank"></div>

	<div class="func"></div>

	<div class="bottom_ad"><a href="#"><img border="0" width="100%" height="100%" src="/static/images/bottomlogin.gif" /></a></div>

</div>
</body>
</html>

